<template>
  <!-- <div>home</div> -->
  <init-model :video-info="videoInfo" @getPosition="getPosition" :tallList="tallList" />
</template>

<script setup>
import { ElMessage } from 'element-plus'
import { onMounted, ref } from 'vue'
import { addTall, getTall, login, videoList,delTall } from '@/api/three'
let videoInfo = ref([])
let tallList = ref([])
onMounted(() => {
  login({ name: 'admin', pwd: '123456' }).then((res) => {
    localStorage.setItem('authToken', res.token)
  })
  getVideo()
  getTalls()

})

const getTalls = () => {
  
  getTall().then((res) => {
    tallList.value = res.data
   })
}

const getVideo = () => {
  videoList().then((res) => {
    videoInfo.value = res.data
  })
}

const getPosition = (obj) => {
  console.log('getPosition', obj);
  addTall({ tall: obj.x.toFixed(5), wide:obj.y.toFixed(5), long: obj.z.toFixed(5), video_id: obj.currentIndex }).then((res) => {
    if (res.code == 1) {
      ElMessage({ message: '添加成功！！！', type: 'success' })
        getTalls()
      }
  })
}

const deleteTall = (id) => {
  delTall({ id }).then((res) => {
    if (res.code == 1) {
      ElMessage({ message: '删除成功！！！', type: 'success' })
      getTalls()
      }
  })
}
</script>

<style lang="scss" scoped></style>
